<!-- 项目班组工人统计表 -->
<template>
	<view class="flex-page">
		<bg-search placeholder="请输入项目名称" @search="searchHandler">
			<view class="flex align-center pt-4 font-12 text-grey1 padding-left">
				<view>共计：</view>
				<view class="search-reslut mr-4">
					项目数量<text class="font-red">{{projectCount}}</text>
				</view>
				<view class="search-reslut">
					工人统计<text class="font-red">{{workerCount}}</text>人
				</view>
			</view>
		</bg-search>
		<view class="content-wrap mt-2 flex-1 bg-white">
			<u-list @scrolltolower="loadMore" style="height: calc(100vh - 300rpx);">
				<u-list-item v-for="p, idx in dataList" :key="idx" > 
					<bg-cell2 :show-arrow="true" @click="onTap(p)" >
						<template slot="label">
							<view>
								<bg-desc label="项目名称" :value="p.projectName"></bg-desc>
								<bg-desc label="共计人数" :value="p.workerCount+'人'"></bg-desc>
							</view>
						</template>
					</bg-cell2>
				</u-list-item>
			</u-list>
			<!-- <bg-cell2 :show-arrow="true" @click="onTap" v-for="p, idx in dataList" :key="idx">
				<template slot="label">
					<view>
						<bg-desc label="项目名称" :value="p.projectName"></bg-desc>
						<bg-desc label="共计人数" :value="p.workerCount+'人'"></bg-desc>
					</view>
				</template>
			</bg-cell2> -->
		</view>
	</view>
</template>

<script>
	import {getProjectCount} from "@/api/project.js"
	export default {
		data() {
			return {
				projectCount:0,
				workerCount:0,
				params:{
					projectName:'',
					pageNum:1,
					pageSize:10
				},
				dataList:[]
			}
		},
		mounted() {
			this.getData()
		},
		methods: {
			searchHandler(e){
				this.params.projectName = e
				this.dataList = []
				this.params.pageNum = 1
				this.getData()
			},
			loadMore(){
				if(this.dataList.length < this.projectCount){
					this.params.pageNum += 1
					this.getData()
				}
			},
			getData(){
				getProjectCount(this.params).then(res=>{
					this.dataList = [...this.dataList, ...res.data.projectList]
					this.projectCount = res.data.projectCount
					this.workerCount = res.data.workerCount
				})
			},
			onTap(p){
				uni.navigateTo({
					url:"/pages/attendance/statistics/person?pid=" +p.id
				})
			}
		}
	}
</script>

<style>
.search-reslut {
	
}
</style>
